wayland: Plug some memleaks in DnD/clipboard code
authorCarlos Garnacho <carlosg@gnome.org>
Thu, 25 Jun 2015 12:52:47 +0000 (14:52 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 25 Jun 2015 13:09:56 +0000 (15:09 +0200)
gdk_atom_name() return value must be freed, this code was consistently
not doing so...

gdk/wayland/gdkdnd-wayland.c
gdk/wayland/gdkselection-wayland.c

index fea4480c06dfbc213dd3bb81896e332873d9f165..6bbe3ced0984836fce048a99d31940a7e0ae00cb 100644 (file)
@@ -214,8 +214,10 @@ gdk_wayland_drop_context_set_status (GdkDragContext *context,
 
       if (l)
         {
-          wl_data_offer_accept (wl_offer, context_wayland->serial,
-                                gdk_atom_name (l->data));
+          gchar *mimetype = gdk_atom_name (l->data);
+
+          wl_data_offer_accept (wl_offer, context_wayland->serial, mimetype);
+          g_free (mimetype);
           return;
         }
     }
@@ -353,7 +355,12 @@ _gdk_wayland_window_drag_begin (GdkWindow *window,
                                            gdk_wayland_drag_context_get_selection (context));
 
   for (l = context->targets; l; l = l->next)
-    wl_data_source_offer (context_wayland->data_source, gdk_atom_name (l->data));
+    {
+      gchar *mimetype = gdk_atom_name (l->data);
+
+      wl_data_source_offer (context_wayland->data_source, mimetype);
+      g_free (mimetype);
+    }
 
   wl_data_device_start_drag (gdk_wayland_device_get_data_device (device),
                              context_wayland->data_source,
index d0e7e7d73f6cce2d944c002e0a41cb7e6936a1b3..d1c754cb6ecd0537acdd389ef64883d211dbf76d 100644 (file)
@@ -504,10 +504,16 @@ gdk_wayland_selection_store (GdkWindow    *window,
       if (mode != GDK_PROP_MODE_REPLACE &&
           type != selection->stored_selection.type)
         {
+          gchar *type_str, stored_str;
+
+          type_str = gdk_atom_name (type);
+          stored_str = gdk_atom_name (selection->stored_selection.type);
+
           g_warning (G_STRLOC ": Attempted to append/prepend selection data with "
                      "type %s into the current selection with type %s",
-                     gdk_atom_name (type),
-                     gdk_atom_name (selection->stored_selection.type));
+                     type_str, stored_str);
+          g_free (type_str);
+          g_free (stored_str);
           return;
         }
 
@@ -925,6 +931,7 @@ _gdk_wayland_display_convert_selection (GdkDisplay *display,
 {
   GdkWaylandSelection *wayland_selection = gdk_wayland_display_get_selection (display);
   SelectionBuffer *buffer_data;
+  gchar *mimetype;
 
   if (!wayland_selection->offer)
     {
@@ -944,10 +951,12 @@ _gdk_wayland_display_convert_selection (GdkDisplay *display,
       return;
     }
 
+  mimetype = gdk_atom_name (target);
+
   if (target != gdk_atom_intern_static_string ("TARGETS"))
     wl_data_offer_accept (wayland_selection->offer,
                           _gdk_wayland_display_get_serial (GDK_WAYLAND_DISPLAY (display)),
-                          gdk_atom_name (target));
+                          mimetype);
 
   buffer_data = g_hash_table_lookup (wayland_selection->selection_buffers,
                                      target);
@@ -975,8 +984,7 @@ _gdk_wayland_display_convert_selection (GdkDisplay *display,
         {
           g_unix_open_pipe (pipe_fd, FD_CLOEXEC, NULL);
           wl_data_offer_receive (wayland_selection->offer,
-                                 gdk_atom_name (target),
-                                 pipe_fd[1]);
+                                 mimetype, pipe_fd[1]);
           stream = g_unix_input_stream_new (pipe_fd[0], TRUE);
           close (pipe_fd[1]);
         }
@@ -1001,6 +1009,8 @@ _gdk_wayland_display_convert_selection (GdkDisplay *display,
 
   if (!buffer_data->stream)
     selection_buffer_notify (buffer_data);
+
+  g_free (mimetype);
 }
 
 gint
@@ -1072,7 +1082,12 @@ gdk_wayland_selection_add_targets (GdkWindow *window,
   g_array_append_vals (wayland_selection->source_targets, targets, ntargets);
 
   for (i = 0; i < ntargets; i++)
-    wl_data_source_offer (data_source, gdk_atom_name (targets[i]));
+    {
+      gchar *mimetype = gdk_atom_name (targets[i]);
+
+      wl_data_source_offer (data_source, mimetype);
+      g_free (mimetype);
+    }
 
   if (selection == atoms[ATOM_CLIPBOARD])
     {